package org.dragonnova.meetingapp.model.bean;

import android.net.Uri;

import com.google.gson.GsonBuilder;

import org.dragonnova.meetingapp.utils.Constants;

import java.io.Serializable;
import java.net.SocketAddress;
import java.util.Arrays;

/**
 * 语音数据实体
 * Created by hucn on 2016/5/11 15:45.
 * Description：保存聊天数据的javabean
 */
public class VoiceInfo implements Serializable {

    public static final String CONTENT = "record";
    public final static Uri CONTENT_VOICE_URI = Uri.parse("content://" + Constants.AUTHORITY + "/" + CONTENT);

    public final static String KEY_ID_COLUMN = "_id";
    public static final String KEY_ORG_TRAN_TEXT_COLUMN = "ORG_TEXT";
    public static final String KEY_ORG_PATH_COLUMN = "ORG_PATH";
    public static final String KEY_TRAN_TEXT_COLUMN = "TRAN_TEXT";
    public static final String KEY_INSERT_DATE_COLUMN = "INSERT_DATE";
    public static final String KEY_VOICE_TYPE_COLUMN = "VOICE_LANGUAGE";
    public static final String KEY_VOICE_ORG_COST_TIME_COLUMN = "VOICE_COST_TIME";
    public static final String KEY_VOICE_USER_ID_FOREIGN_COLUMN = "USER_ID";
    public static final String KEY_VOICE_FLAG_COLUMN = "FLAG";
    public static final String KEY_MEETING_ID_COLUMN = "MEETING_ID";


    private final static long serialVersionUID = 1L;
    /**
     * 序列
     */
    private long id;
    /**
     * 原始语音数据
     */
    private byte[] orgData;
    /**
     * 合成语音
     */
    private byte[] tranData;
    /**
     * 原始文字描述
     */
    private String orgContent;
    /**
     * 翻译文字描述
     */
    private String tranContent;
    /**
     * 插入时间
     */
    private long insertTime;
    /**
     * 语音类型，e.英文 c.中文
     */
    private char type;
    /**
     * 原始语音路径
     */
    private String orgPath;
    /**
     * 原始包地址
     */
    private SocketAddress orgAddress;
    /**
     * 原始语音录音时长
     */
    private int orgCostTime;
    /**
     * 用户信息，暂用名称
     */
    private String userId;
    /**
     * 删除标志位
     */
    private int flag;

    private long meetingId;

    public VoiceInfo(String orgContent) {
        this.orgContent = orgContent;
    }

    public VoiceInfo(long id, long insertTime, char type, String orgContent) {
        this.id = id;
        this.insertTime = insertTime;
        this.type = type;
        this.orgContent = orgContent;
    }

    public VoiceInfo(long insertTime, char type, String orgContent) {
        this.insertTime = insertTime;
        this.type = type;
        this.orgContent = orgContent;
    }

    public VoiceInfo(long insertTime, char type, String orgContent, String orgPath) {
        this.insertTime = insertTime;
        this.type = type;
        this.orgContent = orgContent;
        this.orgPath = orgPath;
    }

    public VoiceInfo(String orgContent, String tranContent, long insertTime, char type, String orgPath, int orgCostTime, String userId, int flag) {
        this.orgContent = orgContent;
        this.tranContent = tranContent;
        this.insertTime = insertTime;
        this.type = type;
        this.orgPath = orgPath;
        this.orgCostTime = orgCostTime;
        this.userId = userId;
        this.flag = flag;
    }

    public VoiceInfo(long id, String orgContent, String tranContent, long insertTime, char type, String orgPath, int orgCostTime, String userId, int flag) {
        this.id = id;
        this.orgContent = orgContent;
        this.tranContent = tranContent;
        this.insertTime = insertTime;
        this.type = type;
        this.orgPath = orgPath;
        this.orgCostTime = orgCostTime;
        this.userId = userId;
        this.flag = flag;
    }

    public VoiceInfo(long id, String orgContent, String tranContent, long insertTime, char type, String orgPath, int orgCostTime, String userId, int flag, long meetingId) {
        this.id = id;
        this.orgContent = orgContent;
        this.tranContent = tranContent;
        this.insertTime = insertTime;
        this.type = type;
        this.orgPath = orgPath;
        this.orgCostTime = orgCostTime;
        this.userId = userId;
        this.flag = flag;
        this.meetingId = meetingId;
    }

    public VoiceInfo(String orgContent, String tranContent, long insertTime, char type, String orgPath, int orgCostTime) {
        this.orgContent = orgContent;
        this.tranContent = tranContent;
        this.insertTime = insertTime;
        this.type = type;
        this.orgPath = orgPath;
        this.orgCostTime = orgCostTime;
    }

    public VoiceInfo(long insertTime, char type, byte[] data) {
        this.insertTime = insertTime;
        this.type = type;
        this.orgContent = new String(data);
        this.orgContent.replaceAll("/", "").trim();
    }

    public int getOrgCostTime() {
        return orgCostTime;
    }

    public void setOrgCostTime(int orgCostTime) {
        this.orgCostTime = orgCostTime;
    }

    public SocketAddress getOrgAddress() {
        return orgAddress;
    }

    public void setOrgAddress(SocketAddress orgAddress) {
        this.orgAddress = orgAddress;
    }

    public String getOrgPath() {
        return orgPath;
    }

    public void setOrgPath(String orgPath) {
        this.orgPath = orgPath;
    }

    public long getId() {
        return id;
    }

    public void setId(long id) {
        this.id = id;
    }

    public byte[] getOrgData() {
        return orgData;
    }

    public void setOrgData(byte[] orgData) {
        this.orgData = orgData;
    }

    public byte[] getTranData() {
        return tranData;
    }

    public void setTranData(byte[] tranData) {
        this.tranData = tranData;
    }

    public String getOrgContent() {
        return orgContent;
    }

    public void setOrgContent(String orgContent) {
        this.orgContent = orgContent;
    }

    public String getTranContent() {
        return tranContent;
    }

    public void setTranContent(String tranContent) {
        this.tranContent = tranContent;
    }

    public long getInsertTime() {
        return insertTime;
    }

    public void setInsertTime(long insertTime) {
        this.insertTime = insertTime;
    }

    public char getType() {
        return type;
    }

    public void setType(char type) {
        this.type = type;
    }

    public String getUserId() {
        return userId;
    }

    public void setUserId(String userId) {
        this.userId = userId;
    }

    public int getFlag() {
        return flag;
    }

    public void setFlag(int flag) {
        this.flag = flag;
    }

    public long getMeetingId() {
        return meetingId;
    }

    public void setMeetingId(long meetingId) {
        this.meetingId = meetingId;
    }

    public byte[] encode() {
        String msg = new GsonBuilder().create().toJson(this);
        return msg.getBytes();
    }

    public static VoiceInfo parse(String json) {
        return new GsonBuilder().create().fromJson(json, VoiceInfo.class);
    }

    @Override
    public String toString() {
        return "VoiceInfo{" +
                "\n id=" + id +
                "\n orgData=" + Arrays.toString(orgData) +
                "\n tranData=" + Arrays.toString(tranData) +
                "\n orgContent='" + orgContent + '\'' +
                "\n tranContent='" + tranContent + '\'' +
                "\n insertTime=" + insertTime +
                "\n type=" + String.valueOf(type) +
                "\n orgPath='" + orgPath + '\'' +
                "\n orgAddress=" + orgAddress +
                "\n orgCostTime=" + orgCostTime +
                "\n userId='" + userId + '\'' +
                "\n flag=" + flag +
                '}';
    }
}
